<%--
  Created by IntelliJ IDEA.
  User: 田同学
  Date: 2022/1/5
  Time: 15:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

</head>
<body>
<div class="container">


<!-- 表格展示数据-->
<table id="persontbl">

</table>
</div>

<!-- 模态框（Modal） -->
<div  class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog"  style="width: 80%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">产品设计--产品档案管理--产品档案登记复核</h4>
            </div>
            <div class="modal-body" id="div02">
                <form>
                    <div class="container">
                        <div style="width: 100%;height: 800px;border: #71daec solid;" >
                            <form>
                            <div style="width: 100%;height: 5%;background-color: #71daec"><label style="color: #ffffff;margin: 8px" >主信息</label>
                                <b> <span id="span02" style="position: relative;left: 850px"></span></b>
                            </div>
                                <!--主信息-->
                                <div class="row" id="div01">
                                    <br>
                                    <div class="col-md-6 form-inline">
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <label for="PRODUCT_NAME">产品名称：</label><input type="text" id="PRODUCT_NAME" required="true" maxlength="20" minlength="1"  style="width: 400px" class="form-control" placeholder="请输入产品名称" >
                                    </div>
                                    <div class="col-md-6 form-inline">
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <label for="FACTORY_NAME">制造商：</label><input id="FACTORY_NAME" type="text" style="width: 400px" class="form-control" placeholder="请输入制造商" >
                                    </div>
                                    <br><br><br>
                                    <div class="row">
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label for="FIRST_KIND_ID_01">I&nbsp;级分类：</label><select  id="FIRST_KIND_ID_01"  class="form-control "style="width: 300px">
                                            <option  value="0">---请选择I级分类---</option>
                                        </select>
                                        </div>
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >II&nbsp;级分类：</label><select id="FIRST_KIND_ID_02" class="form-control "style="width: 300px">
                                            <option value="0">---请选择II级分类---</option>
                                        </select>
                                        </div>
                                    </div>
                                    <br>
                                    <div class="row">
                                        <div class="col-md-6 form-inline">
                                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >III&nbsp;级分类：</label><select id="FIRST_KIND_ID_03" class="form-control "style="width: 300px">
                                            <option value="0">---请选择III级分类---</option>
                                        </select>
                                        </div>
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >产品简介：</label><input type="text" class="form-control" id="productNick" placeholder="产品简介" style="width: 300px">
                                        </div>
                                    </div>
                                    <br>
                                    <div class="row">
                                        <div class="col-md-6 form-inline">
                                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label>用途类型：</label><select class="form-control" id="typeY" style="width: 300px">
                                            <option value="0">---请选择用途类型---</option>
                                            <option value="Y001-1">商品</option>
                                            <option value="Y001-2">物料</option>
                                        </select>
                                        </div>
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >档次级别：</label><select class="form-control " id="CLASS_D" style="width: 300px">
                                            <option value="0">---请选择档次级别---</option>
                                            <option value="D001-1">高档</option>
                                            <option value="D001-2">中档</option>
                                            <option value="D001-3">低档</option>
                                        </select>
                                        </div>
                                    </div>
                                    <br>
                                    <div class="row">
                                        <div class="col-md-6 form-inline">
                                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >计量单位：</label><input type="text" id="personalUnit" class="form-control" placeholder="请输入计量单位" style="width: 300px">
                                        </div>
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >计量值：</label><input id="personalValue" type="text" class="form-control" placeholder="请输入计量值" style="width: 300px">
                                        </div>
                                    </div>
                                    <br>
                                    <div class="row">
                                        <div class="col-md-6 form-inline">
                                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >市场单价(元)：</label><input id="listPrice" type="number" class="form-control" required="true"  placeholder="请输入市场单价" style="width: 300px">
                                        </div>
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >计划成本单价：</label><input id="costPrice" type="number" class="form-control" required="true" placeholder="请输入计划成本单价" style="width: 300px">
                                        </div>
                                    </div>
                                </div>
                                <br>
                                <div style="width: 100%;height: 5%;background-color: #71daec"><label style="color: #ffffff;margin: 8px" >辅助信息</label></div>
                                <!--辅助信息-->
                                <div class="row">
                                    <br>
                                    <div class="col-md-6 form-inline">
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <label >保修期：</label><input id="warranty" type="text" style="width: 400px" class="form-control" placeholder="请输入保修日期" >
                                    </div>
                                    <div class="col-md-6 form-inline">
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <label >替代品名称：</label><input id="twinName" type="text" style="width: 400px" class="form-control" placeholder="请输入替代品名称" >
                                    </div>
                                    <br><br><br>
                                    <div class="row">
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >替代品编号：</label><input id="twinId" type="text" style="width: 400px" class="form-control" placeholder="请输入替代品名称" >
                                        </div>
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >生命周期(年)：</label><input id="lifecycle" type="text" style="width: 400px" class="form-control" placeholder="请输入生命周期日期" >
                                        </div>
                                    </div>
                                    <br>
                                    <div class="row">
                                        <div class="col-md-6 form-inline">
                                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >单位：</label><input id="amountUnit" type="text" class="form-control" placeholder="请输入单位" style="width: 300px">
                                        </div>

                                    </div>
                                    <br>
                                    <div class="row">
                                        <div class="col-md-6 form-inline">
                                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label  style="float: left;line-height: 72px;position: relative;left: 60px">供应商集合：</label>
                                            <textarea style="width: 300px;padding-bottom: 40px" id="providerGroup"></textarea>
                                        </div>
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label style="float: left;line-height: 72px;position: relative;left: 54px">产品描述：</label>
                                            <textarea style="width: 300px;padding-bottom: 40px" id="productDescribe"></textarea>
                                            </select>
                                        </div>
                                    </div>
                                    <br>
                                    <div class="row">
                                        <div class="col-md-6 form-inline">
                                            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >登记人：</label><input id="re_id" type="text" class="form-control" placeholder="请输入登记人姓名" style="width: 300px">
                                        </div>
                                        <div class="col-md-6 form-inline">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <label >审核时间：</label><input type="text" id="date02" class="form-control" value="2021-12-30 08:52:12"  disabled style="width: 300px">
                                        </div>
                                    </div>


                                </div>

                            </form>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" id="updatebyDFile">审核通过</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
    <input type="hidden" id="hidde_id" value="">
<script>

    var params = {
        url: "${pageContext.request.contextPath}/dfile.action",
        method: 'GET',                      //请求方式（*）
        toolbar: '#toolbar',              //工具按钮用哪个容器
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否显示分页（*）
        sortable: true,                     //是否启用排序
        sortOrder: "asc",                   //排序方式
        sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
        pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
        pageSize: 5,                     //每页的记录行数（*）
        pageList: [5, 10, 25, 50, 100],        //可供选择的每页的行数（*）
        search: false,                      //是否显示表格搜索
        strictSearch: true,
        showColumns: true,                  //是否显示所有的列（选择显示的列）
        showRefresh: true,                  //是否显示刷新按钮
        minimumCountColumns: 2,             //最少允许的列数
        clickToSelect: true,                //是否启用点击选中行
        height: 500,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
        uniqueId: "id",                     //每一行的唯一标识，一般为主键列
        showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
        cardView: false,                    //是否显示详细视图
        detailView: false,                  //是否显示父子表
        //传递额外的查询用的参数
        queryParams: function (params) {
            //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            var temp = {
                pagesize: params.limit,     //页面大小
                pageno: (params.offset / params.limit) + 1,   //页码
                checkTag:"S001-0"
            };
            return temp;
        },
        columns: [
            // {
            //     title: "全选",
            //     field: "",
            //     checkbox:true
            // },
            {
                title: "产品编号",
                field: "productId"
            },
            {
                title: "产品名称",
                field: "productName"
            },
            {
                title: "用途类型",
                field: "type",
                formatter:function (value) {
                    if (value=="Y001-1"){
                        return "商品";
                    }else
                    if (value=="Y001-2"){
                        return "物料";
                    }
                }
            },
            {
                title: "I分类",
                field: "firstKindName",
            },
            {
                title: "II分类",
                field: "secondKindName",
            },
            {
                title: "III分类",
                field: "thirdKindName",
            },

            {
                title: "产品经理",
                field: "responsiblePerson",
                formatter:function (value) {
                        if (value==0){
                            return "无";
                        }else {
                            return value;
                        }
                }
            },
            {
                title: "审核",
                field: "",
                formatter: function (value, row, index) {
                    return "<input type='button' onclick='openeditwin("+row.id+")'  value='审核' class='btn btn-warning' data-toggle='modal' data-target='#myModal'>";

                }
            }
        ]
    };
    $("#persontbl").bootstrapTable(params);



    sele01(0)
    //获取下拉框值
    function sele01(pId){
        var pId={pId:pId};
        $.get("${pageContext.request.contextPath}/queryPull02.action",
            pId,
            function (data) {
                console.log(data)
                //循环
                $(data).each(function (index,item) {
                    var option=$("<option value='"+item.kindId+""+item.id+"'>"+item.kindName+"</option>")
                    $("#FIRST_KIND_ID_01").append(option)

                })
                $("#FIRST_KIND_ID_01").blur(function () {
                    $("#FIRST_KIND_ID_02>option:gt(0)").remove()
                    $("#FIRST_KIND_ID_03>option:gt(0)").remove()
                    var fir=$("#FIRST_KIND_ID_01").val()
                    sele02(fir.substring(2),fir.substring(0,2))
                })

            }),'json'
    }


    //第二个下拉框
    function sele02(pId,kindId){
        var dco={pId:pId,kindId:kindId};
        $.get("${pageContext.request.contextPath}/queryPull02.action",
            dco,
            function (data) {
                console.log(data)
                //循环
                $("#FIRST_KIND_ID_02>option:gt(0)").remove()
                $(data).each(function (index, item) {
                    var option = $("<option value='"+item.kindId+""+item.id+"'>" + item.kindName + "</option>")
                    $("#FIRST_KIND_ID_02").append(option)
                })
                $("#FIRST_KIND_ID_02").blur(function () {
                    var fir=$("#FIRST_KIND_ID_02").val()
                    sele03(fir.substring(2),fir.substring(0,2))
                })

            }),'json'
    }

    //第三个下拉框
    function sele03(pId,kindId){
        var dco={pId:pId,kindId:kindId};
        $.get("${pageContext.request.contextPath}/queryPull02.action",
            dco,
            function (data) {
                console.log(data)
                //循环
                $("#FIRST_KIND_ID_03>option:gt(0)").remove()
                $(data).each(function (index, item) {
                    var option = $("<option value='"+item.kindId+""+item.id+"'>" + item.kindName + "</option>")
                    $("#FIRST_KIND_ID_03").append(option)
                })

            }),'json'
    }

    // $("#commit").click(function () {
    //     $("#div01 option:selected").each( function () {
    //         if($(this).val()=="0"){
    //             alert($(this).parent().prev().text()+"未选择")
    //             $("#commit").attr("type","")
    //         }
    //     })
    //
    // })
    //审核按钮按下当前行的id
    function openeditwin(id) {

      $.get("${pageContext.request.contextPath}/dfilebyid.action",{id:id},
      function (data) {
          console.log(data)
          //呵呵
          $("#hidde_id").val(id)
          $("#span02").text("档案编号:"+data.productId)
          $("#FACTORY_NAME").val(data.factoryName)
          $("#PRODUCT_NAME").val(data.productName)
          $("#productNick").val(data.productNick)
          $("#personalUnit").val(data.personalUnit)
          $("#personalValue").val(data.personalValue)
          $("#providerGroup").val(data.providerGroup)
          $("#listPrice").val(data.listPrice)
          $("#costPrice").val(data.costPrice)
          $("#warranty").val(data.warranty)
          $("#twinName").val(data.twinName)
          $("#twinId").val(data.twinId)
          $("#lifecycle").val(data.lifecycle)
          $("#amountUnit").val(data.amountUnit)
          $("#productDescribe").val(data.productDescribe)
          $("#re_id").val(data.register)
         $("#typeY option").each(function () {
             if ($(this).val()==data.type){
                 $(this).attr("selected","selected")
             }
         })
          $("#CLASS_D option").each(function () {
              if ($(this).val()==data.productClass){
                  $(this).attr("selected","selected")
              }
          })
          //$("select").each(function (index,item) {
              $("#FIRST_KIND_ID_01 option").each(function () {
                  if ($(this).text()==data.firstKindName){
                      $(this).attr("selected","selected")
                      $("#FIRST_KIND_ID_02>option:gt(0)").remove()
                      $("#FIRST_KIND_ID_03>option:gt(0)").remove()
                      var fir=$(this).val()
                      sele02(fir.substring(2),fir.substring(0,2))
                  }
              })
         setTimeout(function () {
            $("#FIRST_KIND_ID_02 option").each(function () {
                if ($(this).text()==data.secondKindName){
                    $(this).attr("selected","selected")
                    $("#FIRST_KIND_ID_03>option:gt(0)").remove()
                    var fir=$(this).val()
                    sele03(fir.substring(2),fir.substring(0,2))

                    setTimeout(function () {
                        $("#FIRST_KIND_ID_03 option").each(function () {
                            if ($(this).text()==data.thirdKindName){
                                $(this).attr("selected","selected")
                                var fir=$(this).val()
                            }
                        })
                    },200)
                }
            })
        },100)

          //})

      },"json")
        //点击复合获取当前时间
        $(document).ready(function () {
            var starDate =new Date();
            $("#date02").val(starDate.getFullYear()
                +"-"+starDate.getMonth()+1
                +"-"+starDate.getDate()
                +" "+starDate.getHours()
                +":"+starDate.getMinutes()
                +":"+starDate.getSeconds()
            )
        })
    }


    //按下审核通过执行改代码
    $("#updatebyDFile").click(function(){
        var I=$("#FIRST_KIND_ID_01 option:selected").val();
        var II=$("#FIRST_KIND_ID_02 option:selected").val();
        var III=$("#FIRST_KIND_ID_03 option:selected").val();

        var DFileUp={id:$("#hidde_id").val(),changer:$("#FACTORY_NAME").val(),productName:$("#PRODUCT_NAME").val(), productNick:$("#productNick").val(), personalUnit:$("#personalUnit").val(), personalValue:$("#personalValue").val(), providerGroup:$("#providerGroup").val(), listPrice:$("#listPrice").val(), costPrice:$("#costPrice").val(), warranty:$("#warranty").val(), twinName:$("#twinName").val(), twinId:$("#twinId").val(), lifecycle:$("#lifecycle").val(), amountUnit:$("#amountUnit").val(), productDescribe:$("#productDescribe").val(),
            firstKindId:I.substring(0,2),secondKindId:II.substring(0,2),thirdKindId:III.substring(0,2),
            firstKindName:$("#FIRST_KIND_ID_01 option:selected").text(),secondKindName:$("#FIRST_KIND_ID_02 option:selected").text(),thirdKindName:$("#FIRST_KIND_ID_03 option:selected").text(),
            type:$("#typeY option:selected").val(),productClass:$("#CLASS_D option:selected").val(),checkTime:$("#date02").val(),checkTag:"S001-1"
        }
        $.post("${pageContext.request.contextPath}/updatebyDFile.action",DFileUp,
            function (data) {
                alert(data.msg)
                if (data.code==1){
                    $("#persontbl").bootstrapTable("refresh");
                }
            },"json")

    })




</script>
</body>
</html>
